﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Carmack
{
    /// <Subject To Change>
    ///  Timer Class
    /// </summary>
    public class CGameTimer
    {
        double m_time;
        double m_limit;
        double m_factor;
          bool m_state;

        public CGameTimer(double lmt_, double factor_)
        {
            m_time = 0.0;
            m_limit = lmt_;
            m_factor = factor_;
            m_state = false;
        }

        //  Internal interpretation of m_state flag
        //  True means that timer is in progress and it is not free.
        //  False means that the timer is not running and it is free.
        public void Update(GameTime gt_)
        {
            if (!m_state) return;

            if (m_time < m_limit)
            {
                m_time += m_factor;
                m_state = true;
            }
            else
            {
                m_time = 0;
                m_state = false;
            }
        }

        public void Start() { m_state = true; m_time = 0.0; }
        public void Start(double lmt_) { m_state = true; m_time = 0.0; m_limit = lmt_; }
        public void Stop()  { m_state = false; m_time = 0.0; }
        public void Pause() { m_state = false; }
        public void Reset() { m_state = true; m_time = 0.0; }

        // If the timer is not running(or false) it means that it is free
        public bool IsFree() { return !m_state; }
        // If the timer exceeds the limit; return true
        public bool LimitReached() { return !m_state; }

        public double Factor
        {
            get { return m_factor; }
            set { m_factor = value; }
        }
        public bool State
        {
            get { return m_state; }
        }
        public double Limit
        {
            set { m_limit = value; }
            get { return m_limit;  }
        }
    }
}
